package com.android.dopewars;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

public class Bank extends Activity {
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.bank);
        
        ((TextView)findViewById(R.id.bank_quantity)).setText(Integer.toString(0));
        
        ((SeekBar)findViewById(R.id.bank_withdraw_slide)).setMax(Global.dealer_.bank());
        ((SeekBar)findViewById(R.id.bank_withdraw_slide)).setProgress(0);
        ((SeekBar)findViewById(R.id.bank_withdraw_slide)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromTouch) {
				((TextView)findViewById(R.id.bank_quantity)).setText(Integer.toString(progress));
			}
			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onStopTrackingTouch(SeekBar seekBar) {}
        });
        
        ((SeekBar)findViewById(R.id.bank_deposit_slide)).setMax(Global.dealer_.cash());
        ((SeekBar)findViewById(R.id.bank_deposit_slide)).setProgress(0);
        ((SeekBar)findViewById(R.id.bank_deposit_slide)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromTouch) {
				((TextView)findViewById(R.id.bank_quantity)).setText(Integer.toString(progress));
			}
			public void onStartTrackingTouch(SeekBar seekBar) {}
			public void onStopTrackingTouch(SeekBar seekBar) {}
        });
        
        ((Button)findViewById(R.id.bank_withdraw)).setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		// check the validity of the entered text
        		int new_quantity = Integer.parseInt(
        				((EditText)findViewById(R.id.bank_quantity)).getText().toString());
        		if (new_quantity < 0) {
        			new_quantity = 0;
        		}
        		if (new_quantity > Global.dealer_.bank()) {
        			new_quantity = Global.dealer_.bank();
        		}
        		Global.dealer_.setCash(Global.dealer_.cash() + new_quantity);
        		Global.dealer_.setBank(Global.dealer_.bank() - new_quantity);
        		Intent i = new Intent();
        		setResult(RESULT_OK, i);
        		finish();
        	}
        });
        
        ((Button)findViewById(R.id.bank_deposit)).setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        		// check the validity of the entered text
        		int new_quantity = Integer.parseInt(
        				((EditText)findViewById(R.id.bank_quantity)).getText().toString());
        		if (new_quantity < 0) {
        			new_quantity = 0;
        		}
        		if (new_quantity > Global.dealer_.cash()) {
        			new_quantity = Global.dealer_.cash();
        		}
        		Global.dealer_.setCash(Global.dealer_.cash() - new_quantity);
        		Global.dealer_.setBank(Global.dealer_.bank() + new_quantity);
        		Intent i = new Intent();
        		setResult(RESULT_OK, i);
        		finish();
        	}
        });
        
        WindowManager.LayoutParams dialog_params = getWindow().getAttributes();
    	dialog_params.width = WindowManager.LayoutParams.FILL_PARENT;
    	getWindow().setAttributes(dialog_params);
    }
    
    int bank_amount_;
    int cash_amount_;
}
